package cn.edu.ren.dao.imp;

import cn.edu.ren.dao.IStudentDao;
import cn.edu.ren.entity.Student;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @PackageName: cn.edu.ren.dao.imp
 * @ClassName: StudentDaoImp
 * @Description:
 * @author: RZS
 * @date: 2021/6/16  23:44
 */
@Repository
public class StudentDaoImp implements IStudentDao {

    // 定义student数据
    private static Map<Integer, Student> studentMap = new HashMap<>();
    // 初始化Student数据
    static {
        studentMap.put(1, new Student(99, "大锤99", "dc99"));
        studentMap.put(2, new Student(98, "大锤98", "dc98"));
        studentMap.put(3, new Student(97, "大锤97", "dc97"));
    }


    @Override
    public void insert(Student student) {
        studentMap.put(studentMap.size()+1, student);
    }

    @Override
    public Collection<Student> selectAll() {
        return studentMap.values();
    }

    @Override
    public Student selectById(Integer id) {
        return studentMap.get(id);
    }

    @Override
    public void deleteById(Integer id) {
        studentMap.remove(id);
    }

    @Override
    public void updateById(Student student, Integer id) {
        studentMap.put(id, student);
    }
}
